#include "stm32f10x.h"
#include "display.h"
#include "wdtx_lcd5110.h"

void displayInit(void)
{
	LCD5110_prints(0,1,"Fre:");
	LCD5110_printc(8,1,'.');
	LCD5110_prints(11,1,"Hz");
	LCD5110_prints(0,2,"Vpp:");
	LCD5110_printc(8,2,'.');
	LCD5110_printc(11,2,'V');
	LCD5110_prints(0,3,"Rms:");
	LCD5110_printc(8,3,'.');
	LCD5110_printc(11,3,'V');
}

void showOnLcd(uint8_t row,uint32_t value)
{
	uint8_t i = 7;
	LCD5110_printc(10 , row, value%10 + '0');
	value /= 10;
	LCD5110_printc(9 , row, value%10 + '0');
	value /= 10;
	if(value == 0)
	{
		LCD5110_printc(i-- , row, '0');
	}
	while(value != 0)
	{
		LCD5110_printc(i-- , row, value%10 + '0');
		value/=10;
		if(i == 3)
		{
			break;
		}
	}
	while(i > 3)
	{
		LCD5110_printc(i-- , row, ' ');
	}
}

void display(Wave wave)
{
	showOnLcd(1,wave->frequency);
	showOnLcd(2,wave->vpp);
	showOnLcd(3,wave->rms);
}
